;##################################
;命令：
;nasm -f elf64 day7_0vector_2shuffle_1ymm_1double.asm -o main.o && gcc main.o -o main -lc -no-pie && ./main
;输出：
;Value in arr[0] is 2.222200.
;Value in arr[1] is 1.123400.
;Value in arr[2] is 4.444400.
;Value in arr[3] is 3.345600.
;##################################
extern printf

section .data
	msg: db `Value in arr[%d] is %f.\n`, 0
	arr0: dq 1.1111, 2.2222, 3.3333, 4.4444
	arr1: dq 1.1234, 2.2345, 3.3456, 4.4567

section .text
	global main

main:
	push rbp
	mov rbp, rsp

;#################################################
	vmovupd ymm0, [arr0]
	vmovupd ymm1, [arr1]
	;vshufps指令将4个数作为一组进行重新组合
	;vshufpd指令将2个数作为一组进行重新组合
	;取2.222200, 1.123400
	;选2.222200取1
	;选1.123400取0
	;取4.444400, 3.345600
	;选4.444400取1
	;选3.345600取0
	;逆序0101
	vshufpd ymm0, ymm1, 0101b
	vmovupd [arr0], ymm0
;#################################################

	;打印
	mov ebx, 0
	jmp compare

execute:
	mov rdi, msg
	movsxd rsi, ebx
	movq xmm0, qword [arr0 + 8 * ebx]
	movq rdx, xmm0
	call printf

	inc ebx

compare:
	cmp ebx, 4
	jl execute

	mov eax, 0
	leave
	ret
